package com.lwlean.test.utils;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDeserializer implements JsonDeserializer<Date> {
	 @Override
	 public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
		try {
			if (json.getAsString().equals("")
					|| json.getAsString().equals("null")) {
				return null;
			}
		} catch (Exception ignore) {
		}

		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			return sdf.parse(json.getAsString());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
			
	 }
		 
}
